package com.example.lib5.company_interface.StringsAndArrays.test3;

/**
 * 创建日期：2022/6/10 0010 11:48
 *
 * @author tony.sun
 * 类说明：
 */
public class StringOperateImplC implements IStringOperateC{
    @Override
    public String[] split(String str,String dv){
        if (str.isEmpty()){
            System.out.println("输入有误");
            return null;
        }
        String[] res=new String[str.length()];int index=0;
        while (true){
            if (str.contains(dv)){
                int indexof=str.indexOf(dv);
                res[index++]=str.substring(0,indexof);
                str=str.substring(indexof+2);//后移

            }else {
                res[index]=str;
                return res;
            }
        }
    }
    @Override
    public String group(String[] strs,String dv){
        if (strs==null||strs.length==0){
            System.out.println("输入有误");
            return null;
        }
        StringBuilder sb=new StringBuilder();
        for (int i = 0; i < strs.length; i++) {
            sb.append(strs[i]);
            sb.append(dv);
        }
        sb.delete(sb.length()-2,sb.length());
        return sb.toString();
    }
}
